package com.tfy.liquor.dao;

import com.tfy.liquor.bean.UserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Mapper
@Service
public interface UserInfoDao {
    // 添加用户信息
    @Insert("insert into user_info (salt, password, phone, createTime) values ('${salt}', '${password}', '${phone}', '${createTime}')")
//    @Insert("insert into user_info values (null, ${parentId}, '${salt}', '${password}', '${realName}', '${avatar}', '${phone}' '${email}', ${sex}, ${status}, '${createTime}', '${bindTime}')")
    int addUserInfo(UserInfo userInfo);

    // 根据手机号码获取账户信息
    @Select("select * from user_info where phone='${phone}' limit 1")
    UserInfo getUserInfo(String phone);

    // 根据手机号码获取账户id
    @Select("select userId from user_info where phone='${phone}' limit 1")
    Long getUserInfoUserId(String phone);

    // 绑定用户的推荐关系
    @Update("update user_info set parentId=${parentId}, bindTime=${bindTime} where userId=${userId}")
    int bindRecommendRelationship(UserInfo userInfo);

    // 根据用户id获取下级会员信息
    @Select("select userId, phone, bindTime from user_info where parentId=${userId}")
    ArrayList<UserInfo> getLowerUserInfoByUserId(Long userId);

    // 根据下级用户编号获取上级用户信息
    @Select("select userId, parentId, realName, avatar, phone, email from user_info where userId=(select parentId from user_info where userId=${userId})")
    UserInfo getSuperiorUserInfo(Long userId);

}
